﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ContractLibrary;
using System.ServiceModel;

namespace Server
{
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    public class Server : IContractServer
    {
        public static List<ICallbackClient> clientConnected = new List<ICallbackClient>();
        public void Connect()
        { 
            clientConnected.Add(OperationContext.Current.GetCallbackChannel<ICallbackClient>());
            
        }

        public void SendMessage(string message)
        {
            if (clientConnected.Count > 0)
            {
                foreach (ICallbackClient callback in clientConnected)
                {
                    callback.DisplayMessage(message);
                }
            }
        }

        public void voteForPlayer(int idPlayer)
        {
            Console.WriteLine("Un joueur vient de voter pour le joueur" + idPlayer);
            //TODO : ICI UPDATE BDD

            

            ICallbackClient callback = OperationContext.Current.GetCallbackChannel<ICallbackClient>();
            callback.test("Dear Client, the server is calling you");
        }

        public string voteForPlayer2(int idPlayer)
        {
            return "lol";
        }
    }
}
